/* 
	File: contacto
	
	Este archivo administra todo el código JavaScript asociado al HTML contacto.html

	Ver:
	<WebPage>
*/

function Contacto()
{
	var regexp_email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

	this.pres_def_conf =
	{
		form:
		{
			data:
			{
				title:			"Presupuesto",
				show_rows:		false,
				new_row:		true,

				new_row_func:	function(form)
				{
					MessageBox(false, "Petición enviada", "Se ha enviado correctamente su petición.");
				}
			},

			class_names:
			{
				title:		"header",
				content:	"message_box",
				footer:		""
			},
		
			contents:
			{
				form:		function(title, content, footer)
				{
					var div = createElement({ type_node: "div", children: [ content, footer ] });

					return createBorderElement(title, div);
				}
			}
		},

		row:
		{
			data:
			{
				title:		"",
				edit:		false,
				erase:		false,

				url:		"server/presupuesto.php"
			},

			class_names:
			{
				title:		"header",
				content:	"main_content",
				footer:		""
			}
		
		},
	
		fields:
		{
			output:
			{
				class_names:
				{
					div_cell:		"selected_field",
					div_title:		"label",
					div_value:		"input"
				},

				contents:
				{
					div_cell:		function(title, content)
					{
						return createElement({ type_node: "p", children: [ content ] });
					}
				}
			}
		},
			
			
		par:
		{
			input:
			{
				class_names:
				{
					div_cell:		"field selected_field",
					div_title:		"label",
					div_input:		"input",
					div_error:		"fr"
				}
			}
		},

		impar:
		{
			input:
			{
				class_names:
				{
					div_cell:		"field nonselected_field",
					div_title:		"label",
					div_input:		"input",
					div_error:		"fr"
				}
			}
		}
	};


	this.pres_fields_data = [	{ name: "id", type: "int", len: 10, flags: "primary_key not_null" },
								{ name: "name", type: "text", len: 50, flags: "not_null" },
								{ name: "email", type: "text", len: 50, flags: "not_null" },
								{ name: "description", type: "blob", len: 255, flags: "not_null" },
								{ name: "style_desc", type: "blob", len: 255, flags: "not_null" },
								{ name: "colour_1", type: "text", len: 10, flags: "not_null" },
								{ name: "colour_2", type: "text", len: 10, flags: "not_null" },
								{ name: "colour_3", type: "text", len: 10, flags: "not_null" },
								{ name: "cont_forum", type: "int", len: 1, flags: "" },
								{ name: "cont_blog", type: "int", len: 1, flags: "" },
								{ name: "cont_users", type: "int", len: 1, flags: "" },
								{ name: "cont_chat", type: "int", len: 1, flags: "" },
								{ name: "cont_shop", type: "int", len: 1, flags: "" },
								{ name: "updates", type: "int", len: 1, flags: "" } 
							]


	this.pres_field_conf  =
	[
		{ data: { name: "Id", auto_value: true }, input: { contents: { div_cell: function() { return false; } } } },
		{ data: { name: "Nombre:" } },
		{ data: { name: "E-mail:", reg_exp: regexp_email } },
		{ data: { name: "Descripción general:" } },
		{ data: { name: "Descripción del estilo:" } },
		{ data: { name: "Color principal", type: "radio", select_values: { 1: "Azul", 2: "Verde", 3: "Rojo"} } },
		{ data: { name: "Color secundario", type: "select", select_values: ["Marrón", "Amarillo", "Rosita" ] } },
		{ data: { name: "Color de fondo", type: "radio", select_values: ["Azul cielo", "Verde moco", "Rojo Infierno"] } },
		{ data: { name: "Contenido: FORO", type: "checkbox" } },
		{ data: { name: "Contenido: BLOG", type: "checkbox" } },
		{ data: { name: "Contenido: REGISTRO USUARIOS", type: "checkbox" } },
		{ data: { name: "Contenido: CHAT", type: "checkbox" } },
		{ data: { name: "Contenido: TIENDA", type: "checkbox" } },
		{ data: { name: "Actualización de contenidos", type: "checkbox" } }
	];
	

	this.msg_def_conf =
	{
		form:
		{
			data:
			{
				title:			"Enviar un mensaje",
				show_rows:		false,
				new_row:		true,

				new_row_func:	function(form)
				{
					MessageBox(false, "Mensaje enviado", "Se ha enviado su mensaje correctamente.");
				}
			},

			class_names:
			{
				title:		"header",
				content:	"message_box",
				footer:		""
			},
		
			contents:
			{
				form:		function(title, content, footer)
				{
					var div = createElement({ type_node: "div", children: [ content, footer ] });

					return createBorderElement(title, div);
				}
			}
		},

		row:
		{
			data:
			{
				title:		"",
				edit:		false,
				erase:		false,

				url:		"server/message.php"
			},

			class_names:
			{
				title:		"header",
				content:	"main_content",
				footer:		""
			}
		
		},
	
		fields:
		{
			output:
			{
				class_names:
				{
					div_cell:		"selected_field",
					div_title:		"label",
					div_value:		"input"
				},

				contents:
				{
					div_cell:		function(title, content)
					{
						return createElement({ type_node: "p", children: [ content ] });
					}
				}
			}
		},
			
			
		par:
		{
			input:
			{
				class_names:
				{
					div_cell:		"field selected_field",
					div_title:		"label",
					div_input:		"input",
					div_error:		"fr"
				}
			}
		},

		impar:
		{
			input:
			{
				class_names:
				{
					div_cell:		"field nonselected_field",
					div_title:		"label",
					div_input:		"input",
					div_error:		"fr"
				}
			}
		}
	};

	this.msg_fields_data = [	{ name: "id", type: "int", len: 10, flags: "primary_key not_null" },
								{ name: "name", type: "text", len: 50, flags: "not_null" },
								{ name: "email", type: "text", len: 50, flags: "not_null" },
								{ name: "title", type: "text", len: 50, flags: "" },
								{ name: "text", type: "blob", len: 255, flags: "not_null" },
							]


	this.msg_field_conf  =
	[
		{ data: { name: "Id", auto_value: true }, input: { contents: { div_cell: function() { return false; } } } },
		{ data: { name: "Nombre:" } },
		{ data: { name: "E-mail:", reg_exp: regexp_email } },
		{ data: { name: "Asunto:" } },
		{ data: { name: "Mensaje:" } },
	];

}


Contacto.prototype =
{
	onLoadPage:			function()
	{
		this.msg_form = new Form(document.getElementById("contacto_sel2_cont"), this.msg_fields_data, false, this.msg_def_conf, this.msg_field_conf);	
		this.pres_form = new Form(document.getElementById("contacto_sel3_cont"), this.pres_fields_data, false, this.pres_def_conf, this.pres_field_conf);

		this.msg_form.show("output");
		this.pres_form.show("output");

		this.contacto_selected = "contacto_sel1";
		var self = this;
		EH.addEventHandler(document.getElementById("contacto_sel1"), "click", function() { self.contactoChange(EH.getEvent()); }, 100);
		EH.addEventHandler(document.getElementById("contacto_sel2"), "click", function() { self.contactoChange(EH.getEvent()); }, 100);
		EH.addEventHandler(document.getElementById("contacto_sel3"), "click", function() { self.contactoChange(EH.getEvent()); }, 100);

	},

	onUnloadPage:		function()
	{
		this.contacto_selected = "contacto_sel1";
	},

	contactoChange:		function(event)
	{
		if(event.target.nodeName != "DIV")
		{
			var id = event.target.getAttribute("id") ? event.target.getAttribute("id") : event.target.parentNode.getAttribute("id");

			if(this.contacto_selected && document.getElementById(this.contacto_selected + "_cont"))
			{
				document.getElementById(this.contacto_selected + "_cont").className = "hid";
			}

			document.getElementById(id + "_cont").className = "";

			var xobj = new XObject(document.getElementById(id + "_cont"));
			var fifo = new xFuncFIFO;
			var h = xobj.div_cont.offsetHeight;

			xobj.setStyle("opacity", 0);
			xobj.setStyle("height", "0px");

			xobj.setHeight(h + "px", 20);
			xobj.setOpacity(100, 20); 
//			fifo.add(function() { xobj.setHeight(h + "px", 15, 0, fifo); });//
//			fifo.add(function() { xobj.setOpacity(100, 5); xobj.setStyle("height", ""); });
			
			fifo.next();




			this.contacto_selected = id;
		}
	}
}
